namespace Digitalmes.Application.Sys.Dicts.Queries;

/// <summary>
/// 字典分页查询命令。
/// </summary>
public record GetDictListWithPagedQuery(
    int PageNumber,
    int PageSize) : IPagedQuery, IRequest<IResult<PagedList<SysDictDto>>>;

internal sealed class GetDictListWithPagedQueryHandler(IRepository<SysDict> repo) : IRequestHandler<GetDictListWithPagedQuery, IResult<PagedList<SysDictDto>>>
{
    public async Task<IResult<PagedList<SysDictDto>>> Handle(GetDictListWithPagedQuery request, CancellationToken cancellationToken)
    {
        var items = await repo.GetPagedListAsync(request.PageNumber, request.PageSize, cancellationToken);
        return Result.From(items.Adapt<PagedList<SysDictDto>>());
    }
}
